package conference.view;

import org.gstreamer.Element;
import org.gstreamer.ElementFactory;
import org.gstreamer.Pipeline;
import org.gstreamer.State;
import org.gstreamer.StateChangeReturn;

/**
 * 
 * @author Romain
 *
 * a class to play a basic ring tone
 * it comes with a constructor, and 2 methods (start() and stop())
 *
 */
public class Ring {
	private Pipeline ringPipeline;
	private Element ringSrc;
	private Element audioConvert;
	private Element ringOutput;
	
	public Ring(){
		ringSrc = ElementFactory.make("testaudiosrc", "ringSrc");
		audioConvert = ElementFactory.make("audioconvert", "audioConvert");
		ringOutput = ElementFactory.make("autoaudiosink", "ringOutput");
		ringPipeline = new Pipeline("ringPipeline");
		ringPipeline.addMany(ringSrc, audioConvert, ringOutput);
		ringSrc.link(audioConvert);
		audioConvert.link(ringOutput);
	}
	
	/**
	 * starts the audio Pipeline that plays a ring tone.
	 */
	public void start(){
		StateChangeReturn ringStartResult = ringPipeline.setState(State.PLAYING);
		System.out.println("Ring: Pipeline starting..."+ringStartResult);
	}
	
	/**
	 * stops the audio Pipeline. The ring tone will stop.
	 */
	public void stop(){
		StateChangeReturn ringStopResult = ringPipeline.setState(State.NULL);
		System.out.println("Ring: Pipeline stoping..."+ringStopResult);
	}

}
